package com.music.music.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.music.music.domain.Music;
import com.music.music.domain.Singer;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * Author 史豪通
 * Date 2024/10/25 15:14
 */
@Data
public class MusicVo extends Music {
    private List<Singer> singerList;
    private String singerStr;
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private List<Long> singerIds;

    public String getSingerStr() {
        if (singerList.isEmpty()) return "";
        if (singerList.size() == 1) {
            return singerList.get(0).getSingerName();
        }
        StringBuilder sb = new StringBuilder();
        singerList.forEach(singer -> sb.append(singer.getSingerName()).append("/"));
        return sb.substring(0, sb.length() - 1);
    }

    /*public List<Long> getSingerIds() {
        List<Long> singerIds = new ArrayList<>();
        for (Singer singer : singerList) {
            singerIds.add(singer.getSingerId());
        }
        return singerIds;
    }*/

    public List<Long> getSingerIds() {
        List<Long> singerIds = new ArrayList<>();// 必须加上
        singerList.forEach(singer -> singerIds.add(singer.getSingerId()));
        return singerIds;
    }

    public List<Long> getWebSingerIds() {
        return singerIds;
    }
}
